import * as util from '@/assets/js/util'

export const setUser = (context, user) => {
  const { commit } = context
  commit('setUser', user)
}

export const login = async (context, user) => {
  util.localStorage.set('userId', user.userId)
  util.localStorage.set('login', true)
}

export const logout = (context) => {
  const { commit } = context
  commit('logout')
  util.localStorage.remove('userId')
  util.localStorage.remove('login')
}

export const setInfo = (context, info ) => {
  const { user, educationList, gradeList } = info;
  const { commit } = context
  commit('setUser', user)
  commit('setEducationList', educationList)
  commit('setGradeList', gradeList)
  util.localStorage.set('user', user)
  util.localStorage.set('educationList', educationList)
  util.localStorage.set('gradeList', gradeList)

}

export const removeInfo = () => {
  util.localStorage.remove('user')
  util.localStorage.remove('educationList')
  util.localStorage.remove('gradeList')
}